/*
 * pps_bom
 */
package com.pitop.project.ctrl;

import com.alibaba.fastjson.JSON;
import com.pitop.core.tools.StringTools;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;
import java.util.HashMap;

import com.pitop.core.entity.BeanRet;
import com.pitop.core.entity.Page;
import com.pitop.core.tools.redis.RedisUtils;
import com.pitop.project.entity.ProjectBom;
import com.pitop.project.service.ProjectBomSV;

/**
 * 项目bom关联 控制器
 *
 * @author berton
 */
@RestController
@RequestMapping("/projectBom")
@Slf4j
@Api(value = "项目bom关联控制器", description = "项目bom关联控制器")
public class ProjectBomCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private ProjectBomSV projectBomSV;

    /**
     * 查询ProjectBom一个详情信息
     *
     * @param id
     * @param projectCode 项目编码
     * @param bomCode     bom编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询ProjectBom一个详情信息", notes = "查询ProjectBom一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "projectCode", value = "项目编码", dataType = "java.lang.String", paramType = "query"),
            @ApiImplicitParam(name = "bomCode", value = "bom编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public ProjectBom load(Long id, String projectCode, String bomCode) {
        if (id == null && StringTools.isEmpty(projectCode) && StringTools.isEmpty(bomCode)) {
            return null;
        }
        ProjectBom projectBom = projectBomSV.load(id, projectCode, bomCode);
        log.info(JSON.toJSONString(projectBom));
        return projectBom;
    }

    /**
     * 查询ProjectBom一个详情信息，(将查询关联数据)
     *
     * @param id
     * @param projectCode 项目编码
     * @param bomCode     bom编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询ProjectBom一个详情信息", notes = "查询ProjectBom一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "projectCode", value = "项目编码", dataType = "java.lang.String", paramType = "query"),
            @ApiImplicitParam(name = "bomCode", value = "bom编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/get")
    @ResponseBody
    public ProjectBom get(Long id, String projectCode, String bomCode) {
        if (id == null) {
            return null;
        }
        if (projectCode == null) {
            return null;
        }
        if (bomCode == null) {
            return null;
        }
        ProjectBom projectBom = projectBomSV.get(id, projectCode, bomCode);
        log.info(JSON.toJSONString(projectBom));
        return projectBom;
    }

    /**
     * 根据条件id查询ProjectBom一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询ProjectBom一个详情信息", notes = "查询ProjectBom一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public ProjectBom loadById(@PathVariable Long id) {
        if (id == null) {
            return null;
        }
        ProjectBom projectBom = projectBomSV.loadById(id);
        log.info(JSON.toJSONString(projectBom));
        return projectBom;
    }

    /**
     * 根据条件projectCode查询ProjectBom一个详情信息
     *
     * @param projectCode 项目编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询ProjectBom一个详情信息", notes = "查询ProjectBom一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectCode", value = "项目编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/projectCode/{projectCode}")
    @ResponseBody
    public ProjectBom loadByProjectCode(@PathVariable String projectCode) {
        if (projectCode == null) {
            return null;
        }
        ProjectBom projectBom = projectBomSV.loadByProjectCode(projectCode);
        log.info(JSON.toJSONString(projectBom));
        return projectBom;
    }

    /**
     * 根据条件bomCode查询ProjectBom一个详情信息
     *
     * @param bomCode bom编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询ProjectBom一个详情信息", notes = "查询ProjectBom一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bomCode", value = "bom编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/bomCode/{bomCode}")
    @ResponseBody
    public ProjectBom loadByBomCode(@PathVariable String bomCode) {
        if (bomCode == null) {
            return null;
        }
        ProjectBom projectBom = projectBomSV.loadByBomCode(bomCode);
        log.info(JSON.toJSONString(projectBom));
        return projectBom;
    }

    /**
     * 根据条件id查询ProjectBom一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询ProjectBom一个详情信息", notes = "查询ProjectBom一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/get/id/{id}")
    @ResponseBody
    public ProjectBom getById(@PathVariable Long id) {
        if (id == null) {
            return null;
        }
        ProjectBom projectBom = projectBomSV.getById(id);
        log.info(JSON.toJSONString(projectBom));
        return projectBom;
    }

    /**
     * 根据条件projectCode查询ProjectBom一个详情信息
     *
     * @param projectCode 项目编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询ProjectBom一个详情信息", notes = "查询ProjectBom一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectCode", value = "项目编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/get/projectCode/{projectCode}")
    @ResponseBody
    public ProjectBom getByProjectCode(@PathVariable String projectCode) {
        if (projectCode == null) {
            return null;
        }
        ProjectBom projectBom = projectBomSV.getByProjectCode(projectCode);
        log.info(JSON.toJSONString(projectBom));
        return projectBom;
    }

    /**
     * 根据条件bomCode查询ProjectBom一个详情信息
     *
     * @param bomCode bom编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询ProjectBom一个详情信息", notes = "查询ProjectBom一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bomCode", value = "bom编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/get/bomCode/{bomCode}")
    @ResponseBody
    public ProjectBom getByBomCode(@PathVariable String bomCode) {
        if (bomCode == null) {
            return null;
        }
        ProjectBom projectBom = projectBomSV.getByBomCode(bomCode);
        log.info(JSON.toJSONString(projectBom));
        return projectBom;
    }

    /**
     * 查询ProjectBom信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询ProjectBom信息集合", notes = "查询ProjectBom信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public List<ProjectBom> list(@RequestBody @ApiIgnore ProjectBom projectBom, Integer curPage, Integer pageSize) {
        Page<ProjectBom> page = new Page<ProjectBom>(pageSize, curPage);
        List<ProjectBom> projectBoms = projectBomSV.list(projectBom, page.genRowStart(), page.getPageSize());
        int total = projectBomSV.count(projectBom);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return projectBoms;
    }

    /**
     * 查询ProjectBom信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询ProjectBom信息集合", notes = "查询ProjectBom信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "projectCode", value = "项目编码", paramType = "query"),
            @ApiImplicitParam(name = "bomCode", value = "bom编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public List<ProjectBom> listByPk(Long id, String projectCode, String bomCode, Integer curPage, Integer pageSize) {
        Page<ProjectBom> page = new Page<ProjectBom>(pageSize, curPage);
        List<ProjectBom> projectBoms = projectBomSV.list(id, projectCode, bomCode, page.genRowStart(), page.getPageSize());
        int total = projectBomSV.count(id, projectCode, bomCode);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return projectBoms;
    }

    /**
     * 统计ProjectBom信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计ProjectBom信息数量根据主键", notes = " 统计ProjectBom信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "projectCode", value = "项目编码", paramType = "query"),
            @ApiImplicitParam(name = "bomCode", value = "bom编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(Long id, String projectCode, String bomCode) {
        return projectBomSV.count(id, projectCode, bomCode);
    }

    /**
     * 统计ProjectBom信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计ProjectBom信息数量", notes = "统计ProjectBom信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "projectCode", value = "项目编码", paramType = "query"),
            @ApiImplicitParam(name = "bomCode", value = "bom编码", paramType = "query")
    })
    @PostMapping(value = "/count")
    @ResponseBody
    public Integer count(@RequestBody ProjectBom projectBom) {
        return projectBomSV.count(projectBom);
    }

    /**
     * 创建ProjectBom
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建ProjectBom", notes = "创建ProjectBom")
    @ApiImplicitParams({
    })
    @PostMapping("/build")
    @ResponseBody
    public ProjectBom build(@RequestBody @ApiIgnore ProjectBom projectBom) {
        projectBomSV.save(projectBom);
        return projectBom;
    }

    /**
     * 修改ProjectBom
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改ProjectBom", notes = "修改ProjectBom")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "projectCode", value = "项目编码", paramType = "query"),
            @ApiImplicitParam(name = "bomCode", value = "bom编码", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public ProjectBom modify(@RequestBody @ApiIgnore ProjectBom projectBom) {
        projectBomSV.modify(projectBom);
        return projectBom;
    }

    /**
     * 删除ProjectBom
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除ProjectBom", notes = "删除ProjectBom")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "projectCode", value = "项目编码", paramType = "query"),
            @ApiImplicitParam(name = "bomCode", value = "bom编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(Long id, String projectCode, String bomCode) {
        projectBomSV.delete(id, projectCode, bomCode);
        return BeanRet.create(true, "删除ProjectBom成功");
    }
}
